<%@ page import="java.util.Date" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <style rel="stylesheet" type="text/css">
        input[type="text"]{width: 440px;height: 25px}
    </style>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.1.min.js"></script>
    <script>
        $(function () {
            /*添加表单信息至后台*/
            $("#submit").click(function () {
                obj = document.getElementsByName("tp");
                var check_val = [];
                for(k in obj){
                    if(obj[k].checked)
                        check_val.push(obj[k].value);
                }
                var tpList = JSON.stringify(check_val);
                $.ajax({
                    url:"/addBooks.do",
                    dataType:"json",
                    data:{
                        bookCode:$("#bookCode").val(),
                        bookName:$("#bookName").val(),
                        bookAuthor:$("#bookAuthor").val(),
                        publishDate:$("#publishDate").val(),
                        bookTypeID:tpList
                    },
                    type:"post",
                    success:function (data) {
                        var flag=data.addFlag==true?"添加成功":"添加失败";
                        alert(flag);
                        location.href="/index.jsp";
                    }
                })
            })

            /*返回首页*/
            $("#backsapce").click(function () {
                location.href="/index.jsp";
            })


        })

    </script>
</head>
<body>

<div class="total">

    <h2>图书管理系统</h2>
    <hr>

    <div class="tablecss" style="margin-left: 242px">
        <form action="" method="post" id="iForm" enctype="multipart/form-data">
            <table border="1" cellspacing="0" cellpadding="5px" style="width: 570px">
                <tr>
                    <td class="basic">图书编号</td>
                    <td><input type="text" name="bookCode" id="bookCode"></td>
                </tr>
                <tr>
                    <td class="basic">图书名称</td>
                    <td><input type="text" name="bookName" id="bookName"></td>
                </tr>
                <tr>
                    <td class="basic">图书类别</td>
                    <td>
                        文史类:
                        <input type="checkbox" name="tp" value="1">
                        理工类:
                        <input type="checkbox" name="tp" value="2">
                        教育类:
                        <input type="checkbox" name="tp" value="3">
                        其他类:
                        <input type="checkbox" name="tp" value="4">
                    </td>
                </tr>
                <tr>
                    <td class="basic">作&nbsp;&nbsp;&nbsp;者</td>
                    <td><input type="text" name="bookAuthor" id = "bookAuthor"></td>
                </tr>
                <tr>
                    <td class="basic">出版时间</td>
                    <td><input type="date" name="publishDate" id="publishDate" value="<fmt:formatDate value='<%=new Date()%>' pattern="yyyy-MM-dd"/>"></td>
                </tr>
            </table>
            <div class="button">
                <input type="button" value="提交" id="submit">&nbsp;
                <input type="button" value="取消" id="backsapce">
            </div>
        </form>

    </div>
</div>
</body>

</html>